<template>
  <lb-layout
    v-loading="$store.getters.loading"
    element-loading-text="拼命加载中"
    element-loading-spinner="el-icon-loading"
    element-loading-background="#a19f9fb0;"
    :paddBottom="5"
  >
    <aps-form
      :config="apsForm.formConfig"
      :model="apsForm.formData"
      :formRef="apsForm.formRef"
      :labelWidth="apsForm.labelWidth"
      ref="form"
    ></aps-form>
    <lb-table
      style="width: 50%"
      :merge="mergeArr"
      :column="tableData.column"
      :data="tableData.data"
      border
      :height="700"
      pagination
      background
      layout="total, sizes, prev, pager, next, jumper"
      :page-sizes="[10, 20, 30, 40]"
      :pager-count="5"
      :current-page.sync="currentPage"
      :total="total"
      :page-size="pageSize"
      @size-change="handleSizeChange"
      @p-current-change="handleCurrentChange"
    >
    </lb-table>
  </lb-layout>
</template>

<script>
import { getStandbookYearlist } from "@/api/standingbook/newstandingbook.js";
export default {
  components: {},
  data() {
    return {
      mergeArr: ["year"],
      apsForm: {
        formRef: "form",
        labelWidth: "auto",
        formData: {},
        formConfig: {
          formAttr: {
            inline: true,
            size: "small",
          },
          properties: {
            year: {
              label: "年份:",
              typeName: "el-date-picker",
              type: "year",
              size: "small",
              "value-format": "yyyy",
              placeholder: "请选择年份",
              "picker-options": {
                disabledDate(time) {
                  let date = new Date();
                  return time.getFullYear() > date.getFullYear();
                },
              },
            },
          },
          formSoltButton: [
            {
              label: "搜索",
              type: "primary",
              typeName: "el-button",
              size: "small",
              icon: "el-icon-search",
              click: this.handlerSearchDetail,
            },
            {
              label: "重置",
              typeName: "el-button",
              size: "small",
              icon: "el-icon-refresh-left",
              click: this.handleReset,
            },
          ],
        },
      },
      currentPage: 1,
      pageSize: 10,
      total: 0,
      tableData: {
        column: [
          {
            prop: "year",
            label: "年度",
            width: 100,
            align: "center",
            showOverflowTooltip: true,
          },
          {
            prop: "organizationName",
            label: "报送单位",
            minWidth: 100,
            align: "center",
            showOverflowTooltip: true,
          },
          {
            label: "操作",
            width: 120,
            fixed: "right",
            render: (h, scope) => {
              let that = this;
              let a;
              a = (
                <el-button
                  type="text"
                  size="small"
                  icon="el-icon-view"
                  v-hasPermi={["system:year:query"]}
                  onClick={() => {
                    that.$router.push({
                      name: "standingbookCollect6",
                      query: {
                        type: "3",
                        id: scope.row.id,
                        year: scope.row.year,
                        organizationName: scope.row.organizationName,
                      },
                    });
                  }}
                >
                  查看
                </el-button>
              );
              return <div>{a}</div>;
            },
          },
        ],
        data: [],
      },
    };
  },
  created() {},
  mounted() {
    this.handlerSearchDetail();
  },
  methods: {
    async initData(data) {
      let that = this;
      let query = {
        ...data,
      };
      query.pageNum = that.currentPage;
      query.pageSize = that.pageSize;
      that.$store.commit("app/updateApiCount", "add");
      await getStandbookYearlist(query)
        .then((res) => {
          that.$store.commit("app/updateApiCount");
          if (res.code === 700) {
            this.$message.warning(res.msg);
            return false;
          }
          that.tableData.data = res?.rows ?? [];
          that.total = res?.total ?? 0;
        })
        .catch((err) => {
          that.$store.commit("app/updateApiCount");
          // this.$message.error("系统错误,请联系管理员!");
        });
    },
    // 搜索
    handlerSearchDetail() {
      const { year, ...other } = this.$refs?.form?.getFieldsValue();
      const data = {
        ...other,
      };
      if (year) {
        data.year = year + "年";
      }
      this.initData(data);
    },
    // 重置
    handleReset() {
      this.$refs?.form?.resetFields();
      this.handlerSearchDetail();
    },
    handleSizeChange(val) {
      this.currentPage = 1;
      this.pageSize = val;
      this.handlerSearchDetail();
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.handlerSearchDetail();
    },
  },
};
</script>

<style lang="scss" scoped></style>
